package com.google.code.coma.gui.space;

import com.google.code.coma.gui.DataProvider;
import com.google.code.coma.space.util.SpaceManager;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.mozartspaces.core.*;

import java.net.URI;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public abstract class AbstractSpaceDataProvider<T> implements DataProvider<T>{
	protected MzsCore core;

	protected Capi capi;

	protected ContainerReference containerReference;

	protected ObservableList<T> data = FXCollections.observableArrayList();

	public AbstractSpaceDataProvider(String spaceURI, String container) {
		core = DefaultMzsCore.newInstance(0);
		capi = new Capi(core);
		try {
			containerReference = SpaceManager.getOrCreateNamedContainer(URI.create(spaceURI), container, capi);
		} catch (MzsCoreException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public void shutdown() {
		core.shutdown(false);
	}
}
